<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/jquery-3.5.1.min.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<script src="/layui/jquery-3.5.1.min.js"></script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addProduct">添加产品</button>
    </div>
</script>
<form>
    搜索产品：
    <div class="layui-inline">
        <input class="layui-input" name="id" id="productFind" autocomplete="off">
        <!--<select name="dictionary.id" lay-verify="required" lay-search="">
            <option th:each="dictionaryPH:${}" th:value="${dictionaryPH.id}" th:text="${dictionaryPH.value}"></option>&ndash;&gt;
        </select>-->
    </div>
    <button class="layui-btn" id="searchByProduct">按品名搜索</button>
    <button class="layui-btn" id="searchCustomer">按公司搜索</button>
    <button class="layui-btn" type="reset" >重置</button>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>



<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>
</script>


<script src="/layui/layui.js" charset="utf-8"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    $(function () {

    });
    layui.use(['table','jquery'], function() {
        var table = layui.table
            , $ = layui.jquery;

        table.render({
            id: 'tableAll',
            elem: '#test'
            , url: '/customerInformation/productsData'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , title: '出差审批表'
            , where: {
                productName:"",
                customerName:""
            }
            , cols: [
                [

                    {field: 'dictionaryA.value', title: '产品品类', width: 100, fixed: 'left', unresize: true, sort: true, templet: '<div>{{d.dictionaryA.value}}</div>'}
                   /* , {field: 'abbreviation', title: '简称', width: 100, edit: 'text'}*/
                    , {
                    field: 'dictionaryA_id_type',
                    title: '产品品名',
                    width: 100,
                    edit: 'text',
                    templet: '<div>{{d.dictionaryB.value}}</div>'
                }
                    /*,{field:'address', title:'地址', width:100, edit: 'text'}*/
                    , {field: 'model', title: '型号', width: 100, edit: 'text'}
                    /*,{field:'dictionary_id_ownership', title:'所有制类型', width:100, edit: 'text'}*/
                    , {field: 'goodsSource', title: '产品来源', width: 100, edit: 'text'}
                    , {field: 'goodsTo', title: '产品流向', width: 100, edit: 'text'}
                    , {field: 'supplier.name', title: '所属公司', width: 100, edit: 'text' ,templet: '<div>{{d.supplier.name}}</div>'}
                    /*,{field:'add_time', title:'添加时间', width:100, edit: 'text',templet:'<div>{{ layui.util.toDateString(d.addTime, "yyyy-MM-dd") }}</div>'}*/
                    , {
                    field: '',
                    title: '添加时间',
                    width: 100,
                    edit: 'text',
                    templet: '<div>{{ layui.util.toDateString(d.addTime, "yyyy-MM-dd") }}</div>'
                }
                    /*  ,{field:'', title:'出差时间', width:120, edit: 'text', templet:'<div>{{ layui.util.toDateString(d.travelApplication.planTravelDate, "yyyy-MM-dd") }}</div>' }
                      ,{field:'applicationTime', title:'申请时间', width:150, edit: 'text', sort: true,templet:'<div>{{ layui.util.toDateString(d.travelApplication.addTime, "yyyy-MM-dd") }}</div>'}
                      ,{field:'traveNumber', title:'出差人数', width:80,templet:'<div>{{d.travelApplication.travelNumber}}</div>'}
                      ,{field:'travelApplication.supplier.name', title:'走访单位',width:150,templet:'<div>{{d.travelApplication.supplier.name}}</div>'}
                      ,{field:'planMoney', title:'预算', width:80, sort: true,templet:'<div>{{d.travelApplication.planMoney}}</div>'}*/
                    /*  ,{field:'state', title:'当前状态', width:150}*/
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 100}
                ]
            ]
            , page: true
        });
        $('#searchByProduct').on('click', function () {
            table.reload('tableAll', {
                where: {
                    productName: $('#productFind').val(),
                    customerId: "",
                    /*planTravelDate: null*/
                },
                page: {
                    curr: 2
                }
            });
            return false;
        });
        //条件查询
        $('#searchCustomer').on('click', function () {
            table.reload('tableAll', {
                where: {
                    productName:"",
                    customerName: $('#productFind').val()
                    //planTravelDate: null
                },
                page: {
                    curr: 1
                }
            });
            return false;
        });
        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + '个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;
                case 'addProduct':
                    window.location = '/customerInformation/addProductByCustomer';
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
            ;
        });
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                //layer.alert('编辑行：<br>'+ JSON.stringify(data))
                //alert(data.supplier.id)
                parent.layer.open({
                    title: '产品详情',
                    type: 2,
                    content: '/customerInformation/productsDetailed?productId=' + data.id+"&customerId="+data.supplier.id,
                    area: ['1200px', '600px'],
                    shade: [0.3, '#393D49'],
                    shadeClose: false,
                    moveOut: true,
                })
            }/*else if(obj.event === 'log'){
                window.location.href="/approve/travelLog?id="+data.id;

            }*/
        });
        //监听行工具事件
        /* table.on('tool(test)', function(obj){
            var data = obj.data;
            var id = data.id;

            //console.log(obj)
            if(obj.event === 'edit'){
                $.ajax({
                    url: "/customerInformation/detailedData",
                    type:"post",
                    data: {'customerId':id},
                    success:function (data) {
                        window.location.href="/customerInformation/datailed?customerId="+id;
                    }
                })
            }
        });*/
    });
</script>

</body>
</html>